#include "cf_includes.h"

CCF_Timer* CCF_Timer::pInstance = NULL;
CCF_Timer* CCF_Timer::getClassTimer()
{
	if(pInstance == NULL)
		pInstance = new CCF_Timer();
	return pInstance;
}

CCF_Timer::CCF_Timer()
{
	Pause = false;
	StartTime = 0;
	freq = 0;

	LARGE_INTEGER sfreq;
	QueryPerformanceFrequency(&sfreq);
	freq = sfreq.QuadPart;
}
void CCF_Timer::StartTiming()
{
	LARGE_INTEGER scount;
	QueryPerformanceCounter(&scount);
	StartTime = scount.QuadPart;
}
__int64 CCF_Timer::GetCounter()
{
	LARGE_INTEGER scount;
	QueryPerformanceCounter(&scount);
	return scount.QuadPart;
}
__int64 CCF_Timer::GetTicksCounter()
{
	LARGE_INTEGER scount;
	QueryPerformanceCounter(&scount);
	return (scount.QuadPart)*1000/freq;
}
__int64 CCF_Timer::GetElapsedTime()
{
	if (!Pause) return (GetCounter() - StartTime) * 1000 / freq;
	return 0;
}
void CCF_Timer::setPause()
{
	Pause = !Pause;
}
const bool CCF_Timer::isPause() const
{
	return Pause;
}
double CCF_Timer::ConvertTicksToSecond(__int64 Ticks)
{
	return (double)(Ticks / freq);
}